//
//  JLCFNormalTabBarController.m
//  QTZ
//
//  Created by ski on 2017/10/23.
//  Copyright © 2017年 ski. All rights reserved.
//

#import "JLCFNormalTabBarController.h"

#import "JLCFLoadingView.h"

#import "dElHEfJLCFHomeViewControllerjuYxzb.h"
#import "gUCAmcJLCFListViewControllernRoqhZ.h"
#import "FNNNZXJLCFMineViewControllerLCIDTb.h"

//

@interface JLCFNormalTabBarController ()<JLCFErrorTipsViewDelegate>

@property (nonatomic, strong) MBProgressHUD *noticeView;
@property (nonatomic, strong) JLCFErrorTipsView *JLCFErrorTipsView;

@property (nonatomic, strong) UIView *bgView;//遮盖tabbar


@end

@implementation JLCFNormalTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self defaultTabBar];
    self.delegate = self;

}

- (void)defaultTabBar
{

    self.tabBar.tintColor = Theme_Color;
    
    dElHEfJLCFHomeViewControllerjuYxzb *homeVC = [dElHEfJLCFHomeViewControllerjuYxzb new];
    homeVC.tabBarItem.title = @"首页";
    homeVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"icon_home_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    homeVC.tabBarItem.image = [UIImage imageNamed:@"icon_home_noSel"];
    
    gUCAmcJLCFListViewControllernRoqhZ *listVC = [gUCAmcJLCFListViewControllernRoqhZ new];
    listVC.tabBarItem.title = @"产品";
    listVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"icon_list_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    listVC.tabBarItem.image = [UIImage imageNamed:@"icon_list_noSel"];
    
    FNNNZXJLCFMineViewControllerLCIDTb *mineVC =[FNNNZXJLCFMineViewControllerLCIDTb new];
    mineVC.tabBarItem.title = @"我的";
    mineVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"icon_mine_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    mineVC.tabBarItem.image = [UIImage imageNamed:@"icon_mine_noSel"];
    
    self.viewControllers = @[homeVC, listVC, mineVC];
    
}

- (UIView *)bgView
{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:self.view.bounds];
        _bgView.backgroundColor = QTZ_White;
    }
    return _bgView;
}

- (void)showInView:(UIView *)view
{
    [self hideHud];
    _noticeView = [[MBProgressHUD alloc] initWithView:view];
    [view addSubview:_noticeView];
    _noticeView.userInteractionEnabled = YES;
    _noticeView.bezelView.color = QTZ_Black;
    _noticeView.alpha = .8;
    if (@available(iOS 9.0, *)) {
        [UIActivityIndicatorView appearanceWhenContainedInInstancesOfClasses:@[[MBProgressHUD class]]].color = QTZ_White;
    } else {
        // Fallback on earlier versions
    }
    _noticeView.mode = MBProgressHUDModeIndeterminate;
    _noticeView.detailsLabel.font = FONT(14);
    _noticeView.detailsLabel.textColor = QTZ_White;
    _noticeView.detailsLabel.text = @"加载中...";
    _noticeView.margin = 12.f;
    [_noticeView showAnimated:YES];
}

- (void)hideHud
{
    [_noticeView removeFromSuperview];
    [_noticeView hideAnimated:YES afterDelay:0.f];
}


//网络不好提示
- (void)showErrorTips {
    
    if (!_JLCFErrorTipsView) {
        _JLCFErrorTipsView = [[JLCFErrorTipsView alloc] initWithFrame:self.view.bounds];
        _JLCFErrorTipsView.backgroundColor = QTZ_White;
        [self.view addSubview:_JLCFErrorTipsView];
        _JLCFErrorTipsView.delegate = self;
        
    }
    else
    {
        [_JLCFErrorTipsView didFinishLoading];
    }
    
}

- (void)hideErrorTips {
    [_JLCFErrorTipsView removeFromSuperview];
    _JLCFErrorTipsView = nil;
}

- (void)JLCFErrorTipsViewBeginRefresh:(JLCFErrorTipsView *)tipsView
{
    [self hideErrorTips];
}


#pragma ----- 压缩image---

/**
 *  压缩图片
 *  image:将要压缩的图片   size：压缩后的尺寸
 */
- (UIImage*) OriginImage:(UIImage *)image scaleToSize:(CGSize)size
{
    // 下面方法，第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果，需要传NO，否则传YES。第三个参数就是屏幕密度了
    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
    
    [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
    
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return scaledImage;   //返回的就是已经改变的图片
}

- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    if (self.selectedIndex !=selectedIndex) {
        
        _lastSelectedIndex = self.selectedIndex;
    }
    
    [super setSelectedIndex:selectedIndex];
    
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    NSInteger index = [self.tabBar.items indexOfObject:item];
    _lastSelectedIndex = index;
    DBG(@"tabbar : %ld", (long)index);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
